<%-- 
    Document   : CreateAuction
    Created on : Jul 20, 2013, 11:23:34 PM
    Author     : Ndnam
--%>

<%@page import="classes.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Create Auction</title>
    </head>
    <body>
        <form method="POST">
            Product Type: <input type="text" name="productType" value="${param.producttype}"> Drop down menu<br>
            Product name: <input type="text" name="productName" value="${param.productName}"><br>
            Initial Price: <input type="text" name="initialPrice" value="${param.initialPrice}"><br>
            Begin Time: <input type="text" name="beginTime"  value="${param.begintime}"><br>
            Begin Date <input type="text" name="beginDate"  value="${param.begindate}"><br>
            End Time: <input type="text" name="endTime"  value="${param.endtime}"><br>
            End Date: <input type="text" name="endDate" value="${param.enddate}"><br>
            Payment type: <input type="text" name="paymentType" value="${param.paymenttype}">Check boxes <br>
            Shipment type: <input type="text" name="shipmentType" value="${param.shipmenttype}">Check boxes<br>
            Image: Upload image <br>
            Video: Upload video <br>
            <input type="Submit" value="OK" >
        </form>
    </body>
</html>

<jsp:useBean id="auction" class="classes.Auction"/>
<jsp:setProperty name="auction" property="*"/>
<jsp:useBean id="auctionDAO" class="classes.AuctionDAO"/>
<%
    //If user is not logged in, go back to home
    User user = (User)session.getAttribute("user");
    if (user == null) {
        RequestDispatcher dispatch = request.getRequestDispatcher("Home.jsp");
        dispatch.forward(request, response);
    }

    if (request.getParameter("productName") != null) {
        auction.setCreator(user.getUserID());
        auction.setState("New");
        try {
            auctionDAO.insertAuction(auction);
            RequestDispatcher dispatch = request.getRequestDispatcher("Home.jsp");
            dispatch.forward(request, response);
        } catch (Exception ex) {
            out.println(ex.getMessage());
        }
    } else out.println("Not Succeed");
%>